package com.epfresh.supplier.entity;

import com.epfresh.api.utils.DateUtil;
import com.epfresh.api.utils.FormatUtil;

public class Groupon {

    /* {
         "baseCityName" : "邵阳市",
             "startTime" : "2017-12-12 16:04:22.006",
             "expectedDeliverTime" : "",
             "countUpper" : 1111.0,
             "countLower" : 1.0,
             "agencyCityName" : "银川市",
             "grouponId" : 7,
             "endTime" : "2017-12-13 13:49:51.000",
             "sumProductCount" : 25.0
     }*/
    //watermark 水印图片
    private String watermark;
    //代办店铺的id
    public String getAgencyStoreId() {
        return agencyStoreId;
    }

    public void setAgencyStoreId(String agencyStoreId) {
        this.agencyStoreId = agencyStoreId;
    }

    private String agencyStoreId;
    //代办城市
    private String agencyCityName;
    //基地城市
    private String baseCityName;
    private String reMainSecond;
    //已拼数量
    private Double sumProductCount;
    //预计发货时间
    private String expectedDeliverTime;
    //拼货下限
    private Double countLower;
    //拼货上限
    private Double countUpper;
    private String grouponId;

    private String startTime;

    private String endTime;

    //单位
    private String chargeUnit;

    //商品id
    private String productId;

    private String baseStoreId;

    private boolean isLast;
    private long localeTime;
    public Groupon() {
        localeTime = getNowTime();

    }

    public String getWatermark() {
        return watermark;
    }

    public void setWatermark(String watermark) {
        this.watermark = watermark;
    }

    public boolean isLast() {
        return isLast;
    }

    public void setLast(boolean last) {
        isLast = last;
    }

    public String getChargeUnit() {
        return chargeUnit;
    }

    public void setChargeUnit(String chargeUnit) {
        this.chargeUnit = chargeUnit;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getBaseStoreId() {
        return baseStoreId;
    }

    public void setBaseStoreId(String baseStoreId) {
        this.baseStoreId = baseStoreId;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getAgencyCityName() {
        return this.agencyCityName;
    }

    public void setAgencyCityName(String agencyCityName) {
        this.agencyCityName = agencyCityName;
    }

    public String getBaseCityName() {
        return this.baseCityName;
    }

    public void setBaseCityName(String baseCityName) {
        this.baseCityName = baseCityName;
    }

    public String getReMainSecond() {
        return this.reMainSecond;
    }

    public void setReMainSecond(String reMainSecond) {
        this.reMainSecond = reMainSecond;
    }

    public double getSumProductCount() {
        return this.sumProductCount == null ? 0 : sumProductCount;
    }

    public void setSumProductCount(double sumProductCount) {
        this.sumProductCount = sumProductCount;
    }

    public String getExpectedDeliverTime() {
        return this.expectedDeliverTime;
    }

    public void setExpectedDeliverTime(String expectedDeliverTime) {
        this.expectedDeliverTime = expectedDeliverTime;
    }

    public double getCountLower() {
        return this.countLower == null ? 0 : countLower;
    }

    public void setCountLower(double countLower) {
        this.countLower = countLower;
    }

    public double getCountUpper() {
        return this.countUpper == null ? 0 : countUpper;
    }

    public void setCountUpper(double countUpper) {
        this.countUpper = countUpper;
    }

    public String getGrouponId() {
        return this.grouponId;
    }

    public void setGrouponId(String grouponId) {
        this.grouponId = grouponId;
    }


    public int getPercentPage(){
        if (sumProductCount == null || sumProductCount < 0.001){
            return 0;
        }
        int p = 1;
        if (countUpper != null && countUpper > 0){
            double v = FormatUtil.countDivideDown(sumProductCount , countUpper);
            v = FormatUtil.countMultiply(v,100);
            if (v > 1){
                p = (int) v;
            }
        }
        return p;
    }

    public String getSumUpCount(){
        return FormatUtil.subZeroAndDot(getSumProductCount()) + chargeUnit+"/"+FormatUtil.subZeroAndDot(getCountUpper())+chargeUnit;
    }

    public long getNowTime() {
        return System.currentTimeMillis();
    }

    public long getReminderTime(){

        if (startTime != null && endTime != null){
            long tEnd = DateUtil.formatTimeLong(endTime);
            long tServer = DateUtil.formatTimeLong(startTime);

            long tLocale;
            if(localeTime == 0){
                localeTime = getNowTime();
            }

            if (Math.abs(tServer - localeTime) > 60){
                tLocale = (tServer - localeTime + getNowTime());
            }else {
                tLocale = getNowTime();
            }

         if (tLocale <= tEnd){//活动进行中
                return tEnd - tLocale;
            }else {//活动结束了
                return 0;
            }
        }

        return 0;
    }

}
